//
//  YBDeviceResetPopupVC.swift
//  Moonlight
//
//  Created by Penlon Kim on 2024/1/5.
//  Copyright © 2024 Moonlight Game Streaming Project. All rights reserved.
//

import UIKit
import SnapKit

class YBDeviceResetPopupVC: BaseMaskVC {
    
    // MARK: Lifecycle
    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.addSubview(bgImgView)
        bgImgView.addSubviews([titleLabel, closeBtn, desLabel, cancelBtn, confirmBtn])
        
        bgImgView.snp.makeConstraints { make in
            make.center.equalToSuperview()
            make.width.equalTo(kScreenWidth*0.693)
        }
        
        titleLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(16).priority(.high)
            make.height.equalTo(18)
        }
        
        closeBtn.snp.makeConstraints { make in
            make.size.equalTo(15)
            make.right.equalTo(-10)
            make.top.equalTo(12)
        }
        
        desLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(titleLabel.snp.bottom).offset(27)
            make.left.right.equalToSuperview().inset(24)
        }
        
        cancelBtn.snp.makeConstraints { make in
            make.size.equalTo(CGSizeMake((kScreenWidth*0.693-90)/2, 30))
            make.top.equalTo(desLabel.snp.bottom).offset(24)
            make.left.equalTo(desLabel)
            make.bottom.equalTo(-35)
        }
        
        confirmBtn.snp.makeConstraints { make in
            make.size.centerY.equalTo(cancelBtn)
            make.right.equalTo(desLabel)
        }
        
    }
    
    // MARK: - lazy
    lazy var vm: YBCloudComputerViewModel = {
        let vm = YBCloudComputerViewModel()
        return vm
    }()
    
    private lazy var bgImgView: UIImageView = {
        let iv = UIImageView(image: UIImage(named: "icon_popup_bg"))
        iv.isUserInteractionEnabled = true
        iv.bk_addCornerBorder(radius: 8, borderWidth: 0.1, borderColor: .clear)
        iv.contentMode = .scaleAspectFill
        iv.clipsToBounds = true
        return iv
    }()
    
    private lazy var closeBtn: UIButton = {
        let btn = UIButton(type: .custom)
        btn.setImage(UIImage(named: "icon_popup_close"), for: .normal)
        btn.bk_addTarget { [weak self] sender in
            self?.dismiss(animated: true, completion: nil)
        }
        return btn
    }()
    
    private lazy var titleLabel = self.bk_addLabel(text: "设备重置", font: .systemFont(ofSize: 16, weight: .medium), bgColor: .clear, textColor: ColorDef.dark27, align: .center)
    
    private lazy var desLabel = self.bk_addLabel(text: "正在操作设备重置，会重新启动设备，是否确定重置?", font: .systemFont(ofSize: 14), bgColor: .clear, textColor: ColorDef.gray153)
    
    private lazy var confirmBtn: UIButton = {
        let btn = self.bk_addButton(type: .custom, title: "确定", font: .systemFont(ofSize: 13), bgColor: ColorDef.dark27, titleColor: .white, radius: 8)
        btn.bk_addTarget { [weak self] sender in
            guard let self = self else { return }
            self.vm.req_Reset { ok, obj, msg, code in
                if ok {
                    HintTool.toast("重置成功")
                } else {
                    HintTool.toast(msg)
                }
            }
        }
        return btn
    }()
    
    private lazy var cancelBtn: UIButton = {
        let btn = self.bk_addButton(type: .custom, title: "取消", font: .systemFont(ofSize: 13), bgColor: ColorDef.gray184, titleColor: kRGBColor(19, 25, 44), radius: 8)
        btn.bk_addTarget { [weak self] sender in
            self?.dismiss(animated: true)
        }
        return btn
    }()
    
}
